//  Copyright (c) 2012 M.A. (Thijs) van den Berg, http://sitmo.com/
//
//  Use, modification and distribution are subject to the MIT Software License. 
// (See accompanying file LICENSE.txt or copy at http://www.stdfin.org/LICENSE.txt)


#ifndef STDFIN_DISTRIBUTIONS_GBM_AT_FIXED_TIME_HPP
#define STDFIN_DISTRIBUTIONS_GBM_AT_FIXED_TIME_HPP

#include <cmath>
#include <boost/math/distributions/lognormal.hpp>

namespace stdfin{

// ----------------------------------------------------------------
// PDF
// ----------------------------------------------------------------
template <class RealType>
inline RealType gbm_at_fixed_time_pdf(
        const RealType& S, 
        const RealType& mu, 
        const RealType& sigma, 
        const RealType& t,
        const RealType& x)
{
    RealType location = mu*t + log(S) - sigma*sigma*t/2;
    RealType scale = sigma*sqrt(t);
    
    return boost::math::pdf(
        boost::math::lognormal_distribution<RealType>(location, scale),
        x);
}

// ----------------------------------------------------------------
// CDF
// ----------------------------------------------------------------
template <class RealType>
inline RealType gbm_at_fixed_time_cdf(
        RealType S, 
        RealType mu, 
        RealType sigma, 
        RealType t,
        RealType x)
{
    RealType location = mu*t + log(S) - sigma*sigma*t/2;
    RealType scale = sigma*sqrt(t);
    
    return boost::math::cdf(
        boost::math::lognormal_distribution<RealType>(location, scale),
        x);
}



} // namespace
#endif
